<template>
  <div class="table-wrapper">
    <div class="table-title">
      <ul>
        <li>商品信息</li>
        <li>规格</li>
        <li>实付款</li>
        <li>店员</li>
        <li>收益</li>
        <li>操作</li>
      </ul>
    </div>
    <div v-if="goodsList.length">
      <div v-for="item of goodsList" :key="item.id" class="table-cell">
        <div class="cell-title">
          <p>订单号:{{ item.order_no }}</p>
          <p>下单时间：{{ item.created_at }}</p>
        </div>
        <div class="cell-content">
          <div v-for="(secItem, index) of item.commodity" :key="secItem.ietm_no" class="cell-row">
            <ul>
              <li>
                <div class="img-wrapper">
                  <img :src="secItem.img_show" alt>
                </div>
                <div class="text-wrapper">
                  <div class="text">
                    <p>{{ secItem.name }}</p>
                    <p>单价：￥{{ secItem.price }}</p>
                  </div>
                  <div class="count">×{{ secItem.number }}</div>
                </div>
              </li>
              <li>
                <p>规格</p>
              </li>
              <li>
                <p>￥{{ secItem.price * secItem.number }}</p>
              </li>
              <li>
                <p>{{ item.user }}</p>
              </li>
              <li v-if="index === 0">
                <p>￥{{ status === 'user' ? item.user_earnings : item.shop_earnings }}</p>
              </li>
              <li v-if="index === 0">
                <p class="blue" @click="detail(item)">订单详情</p>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <div v-else class="noResult">暂无数据</div>
    <order-detail :goods-item="goodsItem" :dialog-visible="dialogVisible" @closeDialog="handleCloseDialog" />
  </div>
</template>
<script>
import OrderDetail from './orderDetail'

export default {
  components: {
    OrderDetail
  },
  props: {
    totalSale: {
      type: String,
      default: ''
    },
    goodsList: {
      type: Array,
      default: () => []
    },
    status: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      dialogVisible: false,
      goodsItem: {}
    }
  },
  watch: {
    totalSale(newVal) {
      switch (newVal) {
        case 'assistantTotalSale':
          break
        case 'allSales':
          break
        case 'allEarning':
          break
      }
    }
  },
  methods: {
    detail(item) {
      this.dialogVisible = true
      this.goodsItem = item
    },
    showSecTitle(index) {
      return index % 2 === 0
    },
    handleCloseDialog() {
      this.dialogVisible = false
    }
  }
}
</script>
<style lang="scss" scoped>
ul {
  margin: 0;
  padding: 0;
  li {
    list-style: none;
  }
}
p {
  margin: 0;
}
.table-wrapper {
  width: 100%;
  .table-title {
    height: 45px;
    line-height: 45px;
    font-weight: bold;
    background-color: rgba(250, 250, 250, 1);
    color: rgba(16, 16, 16, 1);
    font-size: 14px;
    text-align: left;
    font-family: Roboto;
    border: 1px solid rgba(235, 238, 245, 1);
    ul {
      display: flex;
      align-items: center;
      li {
        border-right: 1px solid rgba(235, 238, 245, 1);
        padding-left: 20px;
        box-sizing: border-box;
        white-space: nowrap;
        &:nth-child(1) {
          width: 25%;
        }
        &:nth-child(2),
        &:nth-child(3),
        &:nth-child(5) {
          width: 15%;
        }
        &:nth-child(4),
        &:nth-child(6) {
          width: 15%;
        }
      }
    }
  }
  .table-cell {
    width: 100%;
    .cell-title {
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;
      padding-left: 20px;
      height: 30px;
      box-sizing: border-box;
      background-color: rgba(250, 250, 250, 1);
      border-bottom: 1px solid rgba(235, 238, 245, 1);
      border-right: 1px solid rgba(235, 238, 245, 1);
      border-left: 1px solid rgba(235, 238, 245, 1);
      p {
        line-height: 30px;
        color: rgba(51, 51, 51, 1);
        font-size: 12px;
        text-align: center;
        font-family: Roboto;
        &:nth-child(1) {
          margin-right: 25px;
        }
      }
    }
    .cell-content {
      width: 100%;
      .cell-row {
        box-sizing: border-box;
        background: #fff;
        width: 100%;
        border-bottom: 1px solid rgba(235, 238, 245, 1);
        border-left: 1px solid rgba(235, 238, 245, 1);
        border-right: 1px solid rgba(235, 238, 245, 1);
        ul {
          width: 100%;
          display: flex;
          align-items: center;
          li {
            padding: 20px 15px;
            box-sizing: border-box;
            &:nth-child(1) {
              display: flex;
              align-items: center;
              width: 25%;
              .img-wrapper {
                width: 60px;
                height: 60px;
                background-color: #ccc;
                margin-right: 10px;
                img {
                  width: 100%;
                }
              }
              .text-wrapper {
                flex: 1;
                display: flex;
                align-items: center;
                justify-content: space-between;
                .text {
                  p {
                    height: 23px;
                    line-height: 23px;
                    color: rgba(102, 102, 102, 1);
                    font-size: 14px;
                    text-align: left;
                    font-family: Roboto;
                  }
                }
                .count {
                  height: 23px;
                  line-height: 23px;
                  color: rgba(102, 102, 102, 1);
                  font-size: 14px;
                  text-align: center;
                  font-family: Roboto;
                }
              }
            }
            &:nth-child(2),
            &:nth-child(3),
            &:nth-child(5) {
              width: 15%;
              p {
                height: 23px;
                line-height: 23px;
                color: rgba(102, 102, 102, 1);
                font-size: 14px;
                text-align: left;
                font-family: Roboto;
              }
            }
            &:nth-child(4),
            &:nth-child(6) {
              width: 15%;
            }
          }
        }
      }
    }
  }
  .noResult {
      height: 50px;
      line-height: 50px;
      text-align: center;
      color: rgba(102, 102, 102, 1);
      font-size: 14px;
      text-align: center;
      font-family: Roboto;
      border-bottom: 1px solid  rgba(235, 238, 245, 1);
      border-left: 1px solid  rgba(235, 238, 245, 1);
      border-right: 1px solid  rgba(235, 238, 245, 1);
    }
}
.blue {
  color: #1baab0;
  cursor: pointer;
}
</style>
